import axios from '@/libs/api.request'

// 时间转换为日期-> 2019-02-02
export function date2str (date, containtime) {
  if (!date || typeof date === 'string') {
    return date
  }
  var time1 = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()
  time1 += '-' + (month < 10 ? '0' + month : month)
  time1 += '-' + (day < 10 ? '0' + day : day)
  return time1
}

// 生成uuid
export function getUuid () {
  var s = []
  var hexDigits = '0123456789abcdef'
  for (var i = 0; i < 36; i++) {
    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1)
  }
  s[14] = '4' // bits 12-15 of the time_hi_and_version field to 0010
  s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1) // bits 6-7 of the clock_seq_hi_and_reserved to 01
  s[8] = s[13] = s[18] = s[23] = '-'
  var uuid = s.join('')
  return uuid
}

export function date3str (t, date) {
  var date2 = new Date(date)
  var o = {
    'M+': date2.getMonth() + 1,
    'd+': date2.getDate(),
    'h+': date2.getHours(),
    'm+': date2.getMinutes(),
    's+': date2.getSeconds(),
    'q+': Math.floor((date2.getMonth() + 3) / 3),
    'S': date2.getMilliseconds()
  }
  if (/(y+)/.test(t)) {
    t = t.replace(RegExp.$1, (date2.getFullYear() + '').substr(4 - RegExp.$1.length))
  }
  for (var k in o) {
    if (new RegExp('(' + k + ')').test(t)) {
      t = t.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
    }
  }
  return t
}

export function date0str (date, containtime) {
  if (!date || typeof date === 'string') {
    return date
  }
  var time1 = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()
  var hour = date.getHours()
  var min = date.getMinutes()
  time1 += '-' + (month < 10 ? '0' + month : month)
  time1 += '-' + (day < 10 ? '0' + day : day)
  time1 += ' ' + (hour < 10 ? '0' + hour : hour)
  time1 += ':' + (min < 10 ? '0' + min : min)
  return time1
}

// 时间转字符串 年月日时分秒
export function datetime2str (date, containtime) {
  let time1 = date.getFullYear() + ''
  let month = date.getMonth() + 1
  let day = date.getDate()
  let hh = date.getHours()
  let mm = date.getMinutes()
  let ss = date.getSeconds()
  time1 += month < 10 ? '0' + month : month
  time1 += day < 10 ? '0' + day : day
  time1 += hh < 10 ? '0' + hh : hh
  time1 += mm < 10 ? '0' + mm : mm
  time1 += ss < 10 ? '0' + ss : ss
  return time1
}

// 获取诉求评价设置列表
export const getSuqiuPingjiaSettingList = (data) => {
  return axios.request({
    url: '/api/as/cscsst/ywtgAppealAppraise/getSuqiuPingjiaSettingList',
    method: 'post',
    data: data
  })
}
// 新增诉求评价设置
export const createSuqiuPingjiaSetting = (data) => {
  return axios.request({
    url: '/api/as/cscsst/ywtgAppealAppraise/createSuqiuPingjiaSetting',
    method: 'post',
    data: data
  })
}
// 修改诉求评价设置
export const updateSuqiuPingjiaSetting = (data) => {
  return axios.request({
    url: '/api/as/cscsst/ywtgAppealAppraise/updateSuqiuPingjiaSetting',
    method: 'post',
    data: data
  })
}
// 获取诉求评价
export const getSuqiuPingjiaList = (data) => {
  return axios.request({
    url: '/api/as/cscsst/ywtgAppealAppraise/getSuqiuPingjiaList',
    method: 'post',
    data: data
  })
}
